// Copyright@ChenChao

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "AbilitySystemInterface.h"
#include "CCharacter.generated.h"

class UWidgetComponent;
class UCAbilitySystemComponent;
class UCAttributeSet;

UCLASS(Abstract)
class CRUNCH_API ACCharacter : public ACharacter, public IAbilitySystemInterface
{
	GENERATED_BODY()

public:
	
	ACCharacter();
	
	void ServerSideInit();		//服务器端初始化
	void ClientSideInit();		//客户端初始化
	//判断是否有本地玩家控制
	bool IsLocallyControlledByPlayer() const;
	// 只有服务器调用的方法
	virtual void PossessedBy(AController* NewController) override;
protected:
	
	virtual void BeginPlay() override;
	
	/********************************************************************************/
	/*                             GameplayAbilitySystem                            */
	/********************************************************************************/
public:
	virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override;
	
private:
	UPROPERTY(VisibleDefaultsOnly, Category="GamePlay Ability")
	TObjectPtr<UCAbilitySystemComponent> CAbilitySystemComponent;
	
	UPROPERTY(VisibleDefaultsOnly, Category="GamePlay Ability")
	TObjectPtr<UCAttributeSet> CAttributeSet;
	
	/********************************************************************************/
	/*                                       UI                                     */
	/********************************************************************************/
private:
	//控制头顶状态部件
	void ConfigureOverHeadStateWidget();

	//检测状态条可见性
	void UpdateHeadGaugeVisibility();
private:
	UPROPERTY(VisibleDefaultsOnly, Category="UI")
	TObjectPtr<UWidgetComponent> OverHeadWidgetComponent;		//小部件组件

	//计时器频率
	UPROPERTY(EditDefaultsOnly, Category="UI")
	float CheakUpdateRate = 0.2f;

	//状态条可见距离
	UPROPERTY(EditDefaultsOnly, Category="UI")
	float CheakUpdateDistance = 800.f;

	// 距离检测计时器句柄
	FTimerHandle VisibilityCheckTimerHandle;
	
};
